<?php
require_once('mysql.php');

$todolist_id = $_GET['todolist_id'];

$json = array();

// GET THE NAME AND DESCRIPTION
$query = "SELECT list.name, list.description FROM todo_list AS list WHERE list.id=$todolist_id";
$result = mysql_query($query) or die('1'.mysql_error());
$row = mysql_fetch_assoc($result);
$json['name'] = $row['name'];
$json['id'] = $todolist_id;

$query = "SELECT entry.step_no, entry.finished, entry.text, entry.id FROM todo_entry AS entry WHERE entry.list_id=$todolist_id ORDER BY entry.step_no";
$result = mysql_query($query) or die('2'.mysql_error());

$tasks = array();
while($row = mysql_fetch_assoc($result)) {
	$task = array();
	$task['text'] = $row['text'];
	$task['step_no'] = $row['step_no'];
	$task['id'] = $row['id'];
	$task['finished'] = $row['finished'];
	$tasks[] = $task;
	
}
$json['tasks'] = $tasks;
echo json_encode($json);

?>

